const inventors = [
    {first: "Albert", last: "Einstein", year: 1879, passed: 1955},
    {first: "Isaac", last: "NewTon", year: 1643, passed: 1727},
    {first: "Galileo", last: "Galilei", year: 1564, passed: 1642},
    {first: "Marie", last: "Curie", year: 1847, passed: 1934},
    {first: "Johannes", last: "Lepler", year: 1571, passed: 1630},
    {first: "Nicolaus", last: "Copermocis", year: 1473, passed: 1543},
    {first: "Max", last: "Planck", year: 1858, passed: 1947},
]
const people = ['eck,Glenn', 'Becker, Carl', 'Beckett, Samuel', 'Beddoes, Mick', 'Beecher, Henry', 'Beethoven, Ludwig', 'Begin, Menackem', 'Belloc, Hilaire']
//Array pritittype fitten
//1.filten the list of inventors gon those who were born in the 1500's
const fifteen = inventors.filter(inventor => (inventor.year > 1500 && inventor.year < 1600))
console.table(fifteen)
// Array prototype map
//2.give us an array of the inventory ginst and last names
const fullNames = inventors.map(inventor => `${inventor.first} ${inventor.last}`);
console.table(fullNames)
//3.Sort the inventors by birthdate,oldest to yongest
// const ordered = inventors.sort(function (a, b) {
//     if (a.year > b.year) {
//         return 1;
//     } else {
//         return -1;
//     }
//
// });
const ordered = inventors.sort((a, b) => (a.year > b.year) ? 1 : -1)
console.table(ordered)
//4.How many yeares did all the inventons live?

// var totalYears = 0;
// for (var i = 0; i < inventors.length; i++) {
//     totalYears += inventors[i].year
// }
// console.log(totalYears);
const totalYears = inventors.reduce((total, inventor) => {
    return total + (inventor.passed - inventor.year);
}, 0)
console.log(totalYears);
//5 sort the inventors by yeaes lived
const oldest = inventors.sort(function (a, b) {
    const lastGuy = a.passed - a.year;
    const nextGuy = b.passed - b.year;
    return lastGuy > nextGuy ? -1 : 1;

})
console.table(oldest)
//create alist of boulevands in paris tha contain `de` anywhere in the name

// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
/*const category = document.querySelector('.mw-category');
const links = Array.from(category.querySelectorAll('a'));
const de = links.map(link => link.textContent).filter(streetName => streetName.includes('de'));
console.log(de)*/
const category = document.querySelector('.column-content');
const links = Array.from(category.querySelectorAll('a'));
const de = links.map(link => link.textContent).filter(streetName => streetName.includes('de'));
console.log(de)
//7 sort the people alpatically by last name
//17分08s
const alpha = people.sort((lastOne, nextOne) => {
    const [aLast, aFirst] = lastOne.split(", ");
    const [bLast, bFirst] = lastOne.split(", ");
    return aLast > bLast ? 1 : -1;


})

//8 Reduce Exencise
//sum up the instances of each of these
const data = ['car', 'van', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'walk', 'walk']
const transportation = data.reduce(function (obj, item) {
    if (!obj[item]) {
        obj[item] = 0
    }
    obj[item]++;

    return obj;
}, {})
console.log(transportation)